package tq.com.tqstudent.views;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import tq.com.tqstudent.R;
import tq.com.tqstudent.ui.activity.classes.ShareClassActivity;

/**
 * @Author rames
 * @date 2019/4/3 11:04
 */
public class ShareListHeader extends LinearLayout {
    private TextView uploadTV;
    private TextView limitTV;
    private TextView uploadedTV; // 已上传
    private String uploaded;
    private String limit;
    private int index;

    public ShareListHeader(Context context, int index) {
        super(context);
        this.index = index;
        init();
    }

    public ShareListHeader(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init(){
        LayoutInflater.from(getContext()).inflate(R.layout.view_share_list_head, this);
        limitTV = findViewById(R.id.limit_tv);
        uploadedTV = findViewById(R.id.uploaded_tv);
        findViewById(R.id.upload_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                ShareClassActivity.show((Activity) getContext(), index);
            }
        });

        setValue(uploaded, limit);
    }

    public void setValue(String uploaded, String limit){
        this.uploaded = uploaded;
        this.limit = limit;

        if(null != limitTV) {
            limitTV.setText("上限: " + limit + "份");
        }

        if (null != uploadedTV) {
            uploadedTV.setText("已上传: " + uploaded + "份");
        }
    }
}
